package com.wosai.medical.hospital.demo.controller;

import com.wosai.medical.hospital.demo.service.AppSignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 测试-控制器
 *
 * @author yangyong
 * @version 1.0
 * @date 2019/11/30 10:08 上午
 **/
@Slf4j
@RestController
@RequestMapping("/test")
public class TestController extends BaseController {

    @Autowired
    private AppSignService appSignService = null;

    /**
     * 获得签名
     *
     * @param apiAppId
     * @param apiVersion
     * @param apiStamp
     * @param reqArgments
     * @return
     */
    @PostMapping("/sign")
    public String getSign(
            //接入账号(app_id)
            @RequestHeader("api_app_id") final String apiAppId,
            //接口版本号(采用正整数描述)
            @RequestHeader("api_version") final Integer apiVersion,
            //时间戳(13位到毫秒)
            @RequestHeader("api_stamp") final Long apiStamp,
            //请求参数集合
            @RequestBody(required = false) final Map<String, Serializable> reqArgments
    ) {
        //参数签名结果
        Map<String, Serializable> signParams = new HashMap<String, Serializable>() {
            {
                put("api_app_id", apiAppId);
                put("api_version", apiVersion);
                put("api_stamp", apiStamp);
            }
        };
        if (reqArgments != null) {
            signParams.putAll(reqArgments);
        }


        return appSignService.buildSign(signParams);
    }

    ;

}
